//
//  MyGetMoneyChildsViewController.m
//  VEMoneyPorject
//
//  Created by 陈建 on 2018/9/25.
//  Copyright © 2018年 陈建. All rights reserved.
//

#import "MyGetMoneyChildsViewController.h"
#import "MyGetmoneyTableViewCell.h"
#import "MyGetMoneyModel.h"
@interface MyGetMoneyChildsViewController ()

@end

@implementation MyGetMoneyChildsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0,-40, 0);
    // 可以刷新可以加载更多
    self.refreshType = CJBaseTableVcRefreshTypeRefreshAndLoadMore;
    
    
    [self loadData];
    // Do any additional setup after loading the view.
}




- (void)loadData{
    [super loadData];
    [self cj_refresh];
}
- (void)cj_refresh{
    [super cj_refresh];
      [self requestDataWithType:1];
    
}
- (void)cj_loadMore{
    [super cj_loadMore];
    NSLog(@"%ld",self.page);
    [self requestDataWithType:2];
    
    
}

- (void)requestDataWithType:(NSInteger)type{
    
    
    NSString *typeStr = [NSString string];
    
    if (_currentIndex == 0) {
        typeStr = @"0";
    }
    if (_currentIndex == 1) {
        typeStr = @"1";
    }
    NSDictionary *dic = @{@"Userid":[CJUserInfoManager sharedManager].currentUserInfo.USERID,@"type":typeStr,@"Page":@(self.page)};
    CJBaseRequest *request = [CJBaseRequest cj_requestWithUrl:[NSString stringWithFormat:@"%@/VEService/GetCoinRecord.do",kPublicInterfaceAPI] isPost:YES withParameters:dic];
    NSLog(@"%ld",self.page);
    [request cj_sendRequestWithCompletion:^(id response, BOOL success, NSString *message) {
        
        
        [self cj_endRefresh];
        [self cj_endLoadMore];
        NSLog(@"%@",response);
        NSArray *dataArr = response;
        if (dataArr.count == 0) {
            self.page -=1;
            return;
        }
        if (type == 1) {
            self.dataArray = [MyGetMoneyModel mj_objectArrayWithKeyValuesArray:dataArr];
        }
        if (type == 2) {
            [self.dataArray addObjectsFromArray:[MyGetMoneyModel mj_objectArrayWithKeyValuesArray:dataArr]];
        }
        
        [self cj_reloadData];
    }];
    
}





- (NSInteger)cj_numberOfSections{
    return 1;
}

- (NSInteger)cj_numberOfRowsInsection:(NSInteger)section{
    return self.dataArray.count;
}

- (CGFloat)cj_cellHeightAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
    
}

- (CJBaseTableViewCell *)cj_cellAtIndexPath:(NSIndexPath *)indexPath{
    MyGetmoneyTableViewCell *cell = [MyGetmoneyTableViewCell nibWithTableView:self.tableView];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    MyGetMoneyModel *model = self.dataArray[indexPath.row];
    cell.nameLable.text = model.COINTYPE;
    cell.timelable.text = model.GIVETIME;
    cell.getMoneyLable.text = [NSString stringWithFormat:@"+%@",model.COINNUMBER];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
